// ----------------------------------------
// Filename: main.c
// Description: The higest level of the program.
// Author: Jon Maloney
// Date: 9-May-2012
//

//************************************************************
//                    Include .h files
//************************************************************

//************************************************************
//                    Include external references
//************************************************************

#include "hardware_Init.h"
#include "ADC.h"
#include "Config_Handler.h"
#include "serial.h"
#include "Thread.h"
#include "microRTOS.h"
#include "mqueue.h"

//************************************************************
//                    Define Statements
//************************************************************

#define HARDWARE_TEST 1

#if HARDWARE_TEST == 1
	#include "serial.h"
#endif

//************************************************************
//                    Struct, Union, enum Statements
//************************************************************

//************************************************************
//                    Global variables and constants
//************************************************************

//************************************************************
//                    Prototype Private Functions
//************************************************************

void vTask ( void * pvParameters );
void serialTest(void * pvParameters);
void vApplicationIdleHook( void );
//************************************************************
//                    Implementation
//************************************************************


/*
 * Create the demo tasks then start the scheduler.
 */
int main( void )
{
	//Sets up hardware fuses etc.
	//setupHardware();					
	
	//Setup the serial communications
	//xSerialPortInitMinimal(57600, 100, (UINT8)sizeof(SampleConfigurationType), (UINT8)sizeof(SampleType)); 

	//Create the first thread needed for the program
	//	this thread will fork any other threads needed
	//	if new configurations are received.	
	//Thread_Create(ConfigHandler_HandleConfiguration, NULL, 200, 1);
	
	Thread_Create(vApplicationIdleHook, NULL, 200, 0);
	/* Finally start the scheduler. */
	Scheduler_Start();

	/* Will only reach here if there is insufficient heap available to start
	the scheduler. */
	return 0;
}

void vApplicationIdleHook( void )
{
	//Go to sleep here
	for(;;){}
}

void serialTest(void * pvParameters)
{
	UINT8 RxChar  = 0;
	kernelTickType period = 200;
	xComPortHandle serialHandle = xSerialPortInitMinimal( 9600, 100 , sizeof(UINT8), sizeof(UINT8));
	
	for(;;)
	{
		//xSerialPutChar( serialHandle , (1+30), 1 );

		while(xSerialGet( serialHandle , &RxChar, 1 ) == pdTRUE )
		{
			xSerialPut( serialHandle , (void *)1+30, 1 );
			xSerialPut( serialHandle , (void *)RxChar, 1 );
		}
		
		Thread_Delay( period );
	}
}
